package com.yuhs.zixing.study.thread.juc.code004_lock;

import java.util.concurrent.TimeUnit;

/**
 * @description 死锁
 * @author: yuhs
 * @date 2022/3/15 上午11:04
 */
public class C01_DeadLockDemo001 {

    private static String A = "a";
    private static String B = "b";


    private void deadLock() {
        Thread t1 = new Thread(() -> {
            synchronized (A) {
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (B) {
                    System.out.println(1);
                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (B) {
                synchronized (A) {
                    System.out.println(2);
                }
            }
        });

        t1.start();
        t2.start();
    }

    public static void main(String[] args) {
        C01_DeadLockDemo001 c01_deadLockDemo001 = new C01_DeadLockDemo001();
        c01_deadLockDemo001.deadLock();
    }


}
